package ControlLayer;
import java.util.ArrayList;
import ModelLayer.*;

/**
 * Controller class for the address book
 * 
 * @author (kbh, group 1(A)) 
 * @version (2005.03.31, 14-04-2011)
 * (FEN): 2006.03.21: Some changes to the architecture in order to assure layering
 *                    and loose coupling
 */
public class AddressCtr
{
    
    //declaring of instance variables
    private AddressBook addressBook;
    
    /**
     * Constructor for objects of class AddressCtr
     */
    public AddressCtr()
    {
        addressBook = addressBook.getInstance();
    }
    
    /**
     * Creates and adds a person to an ArrayList
     * @param id Id of the person to be added
     * @param name Name of the person to be added
     * @param address Address of the person to be added
     * @param zipCode ZIP Code of the person to be added
     * @param city City of the person to be added
     * @param phoneNumber Phone number of the person to be added
     */
    public void createPerson(int id, String name, String address, int zipCode, String city, int phoneNumber)
    {   
       Person p = new Person(id, name, address, zipCode, city, phoneNumber);
       addressBook.addPerson(p);
    }

    /**
     * Finds a Person
     * @return Returns an object of type Person
     */
    public Person findPerson(int id)
    {
        Person p = null;
        if(addressBook.findPerson(id) != null)
        {
            p = addressBook.findPerson(id);
        }
        else
        {
            System.out.println("No match found!");
        }
        return p;
    }
    
    /**
     * Deletes a person
     * @param id Id of the person to be deleted
     */
    public void deletePerson(int id)
    {
        addressBook.deletePerson(id);
    }
    
    /**
     * Updates a persons data
     * @param id Id of the person to be added
     * @param name Name of the person to be added
     * @param address Address of the person to be added
     * @param zipCode ZIP Code of the person to be added
     * @param city City of the person to be added
     * @param phoneNumber Phone number of the person to be added
     */
    public void updatePerson(int id, String name, String address, int zipCode, String city, int phoneNumber)
    {
        addressBook.updatePerson(id, name, address, zipCode, city, phoneNumber);
    }
    
    /**
     * Calls method to list all persons in the address book
     */
    public void listAllPersons()
    {
          addressBook.listAllPersons();
    }
    
}
